#include "ThreadPool.h"
#include <chrono>
#include <future>
#include <iostream>
#include <thread>
using namespace std;
int main() {
  ThreadPool pool(4);
  cout << "当前线程数量：" << pool.threadCount() << endl;
  cout << "当前线程池状态：" << pool.isRunning() << endl;
  cout << "当前线程池待执行任务数量：" << pool.queueSize() << endl;
  // 添加任务
  for (int i = 0; i < 50; ++i) {
    pool.submit([]() {
      this_thread::sleep_for(chrono::seconds(1));
      cout << "hello" << endl;
    });
  }
  cout << "当前线程数量：" << pool.threadCount() << endl;
  cout << "当前线程池状态：" << pool.isRunning() << endl;
  cout << "当前线程池待执行任务数量：" << pool.queueSize() << endl;
  cout << "等待所有任务执行完毕..." << endl;
  pool.waitForAllTasks();
  cout << "所有任务执行完毕!" << endl;
  // 获取返回值
  future<int> res = pool.submit([]() {
    this_thread::sleep_for(chrono::seconds(2));
    return 10;
  });
  cout << "返回值：" << res.get() << endl;
  return 0;
}